package com.niit.zerotestpdfreader.service;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.niit.zerotestpdfreader.entity.Recent;

import java.util.List;

public class RecentService {

    private DatabaseHelper dbHelper;

    public RecentService(Context context) {
        dbHelper=new DatabaseHelper(context);
    }

    public boolean insertRecent(String path) {

        SQLiteDatabase sdb=dbHelper.getReadableDatabase();

        String sql="insert into recent values(?)";

        Object obj[]={path};

        sdb.execSQL(sql, obj);

        return true;

    }

    public boolean selectRecent(List<Recent> recents) {

        SQLiteDatabase sdb=dbHelper.getReadableDatabase();

//        String sql = "select * from recent";

        Cursor cursor = sdb.query("recent", null, null, null, null, null, null);

        if (cursor.moveToFirst()) {

            do {
                String recentPath = cursor.getString(cursor.getColumnIndex("recentPath"));
                Recent recent = new Recent(recentPath);
                recents.add(recent);
            } while (cursor.moveToNext());

        }

        return true;
    }
}
